package com.hxm.servicebroadcasttest;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;

import static android.content.ContentValues.TAG;

/**
 * Created by hxm on 2017/2/9.
 */

public class HahaService extends Service {

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return new MyBinder();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "onCreate: is executed");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy: is executed");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "onStartCommand: is executed");
        return START_STICKY;
    }

    public class MyBinder extends Binder {
        public void showToast() {
            Log.i(TAG, "showToast: is executed");
            Intent intent = new Intent();
            intent.setAction("com.hxm.ACTION_ONE");
            sendBroadcast(intent);
        }
    }
}
